<?php
/*------------------------------------------------------ */
//-- 下单相关
//-- Author: iqgmy
/*------------------------------------------------------ */
namespace app\shop\controller;
use app\ClientbaseController;
use app\shop\model\OrderModel;
use app\mainadmin\model\PaymentModel;
use app\mainadmin\model\SettingsModel;

class Flow extends ClientbaseController{
	/*------------------------------------------------------ */
	//-- 购物车页
	/*------------------------------------------------------ */
	public function cart(){
        $setcolor = new SettingsModel();
        $color = $setcolor->getRows();
		$this->assign('setcolor',$color['systemcolor']);
		$this->assign('title', '购物车');
		return $this->fetch('index');
	}
    /*------------------------------------------------------ */
    //-- 结算页
    /*------------------------------------------------------ */
    public function checkOut(){
        $setcolor = new SettingsModel();
        $color = $setcolor->getRows();
		$this->assign('setcolor',$color['systemcolor']); 

        $this->assign('title', '结算');
		$this->assign('rec_id', input('rec_id','','trim'));
        return $this->fetch('check_out');
    }
    /*------------------------------------------------------ */
    //-- 下单完成
    /*------------------------------------------------------ */
    public function done(){
        $order_id = input('order_id',0,'intval');
		$type = input('type','','trim');
        $this->assign('title', '订单支付');
        $OrderModel = new OrderModel();
        $orderInfo = $OrderModel->info($order_id);
        if (empty($orderInfo) || $orderInfo['user_id'] != $this->userInfo['user_id']){
            $this->error('订单不存在.');
        }
		$goPay = 0;
        $payment = (new PaymentModel)->where('pay_id', $orderInfo['pay_id'])->find();
        if ($type == 'add' && $orderInfo['pay_status'] == config('config.PS_UNPAYED')){
            if ($orderInfo['is_pay'] == 1){
                $goPay = 1;
            }
        }
        $this->assign('payment', $payment);
		$this->assign('goPay', $goPay);
        $this->assign('orderInfo', $orderInfo);
        return $this->fetch('done');
    }

    public function payment1(){
        $order_id = input('order_id',0,'intval');
        $OrderModel = new OrderModel();
        $orderInfo = $OrderModel->info($order_id);
        $data = (new PaymentModel)->where('pay_id', 3)->find();
        if (empty($data['def_config']) == false){
            $data['def_config'] = json_decode($data['def_config'],true);
        }
        $data['pay_config'] = json_decode(urldecode($data['pay_config']),true);
        $this->assign('orderInfo', $orderInfo);
        $this->assign('data', $data);
//        dump($data["pay_config"]['qcode']);exit;
        return $this->fetch('payment1');
    }

    /*
    * base64格式上传图片
    */
    public function upload_base64_paycode(){
        $bg =input('img');//获取图片流
        $save_url = '/upload/paycode/' . date('Y', time()) . '/' . date('m-d', time());
        try {
            $result = '/upload'.upload_base64($bg,$save_url);
        } catch (\Exception $e) {
            return json_encode(0,$e->getMessage());
        }
//        dump($result);exit;
        $return = array();
        $return['status'] = 200;
        $return['message'] = "上传成功";
        $return['data'] = $result;
//        dump($result['status']);exit;
        return $this->ajaxReturn($return);
    }
}?>